{ParamEdit contains the routines which allow the user to determine
{
{    Whether ionic strength is fixed or calculated
{          (and what the fixed value should be)}
{    Whether log K is calculated from enthalpy and entropy
{          and the solution temperature used for the calculation
{    The maximum error in mole balance tolerated in an converged 'solution'
{    The maximum number of iterations before declaring non-convergence}
{
{    ParamEdit uses Paramform, which is accessed as modal from TitrForm}


unit ParamEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TitrDefs, Editor, StdCtrls, ExtCtrls;

type
  TParamForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    TempEdit: TEdit;
    MuEdit: TEdit;
    MaxItEdit: TEdit;
    TolerEdit: TEdit;
    ExitBtn: TButton;
    ThermoBox: TCheckBox;
    MuBox: TCheckBox;
    UseMuBox: TCheckBox;
    Label5: TLabel;
    HelpBtn: TButton;
    Procedure WriteScreen;
    procedure FormActivate(Sender: TObject);
    procedure TempEditExit(Sender: TObject);
    procedure MuEditExit(Sender: TObject);
    procedure TolerEditExit(Sender: TObject);
    procedure MaxItEditExit(Sender: TObject);
    procedure ExitBtnClick(Sender: TObject);
    procedure ThermoBoxClick(Sender: TObject);
    procedure MuBoxClick(Sender: TObject);
    procedure UseMuBoxClick(Sender: TObject);
    procedure HelpBtnClick(Sender: TObject);
  
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ParamForm: TParamForm;

{******************************************************************************}
{******************************************************************************}

implementation

uses TitrHelp;

{$R *.dfm}

{WriteScreen writes the parameter values (real integer and Boolean) onto
{the form }

Procedure TParamForm.WriteScreen;

begin
      If S.FindMu then MuBox.Checked := False
         else MuBox.Checked := True;
      If S.ThermoCalc then ThermoBox.Checked := True
         else ThermoBox.Checked := False;
      If S.UseMu then UseMuBox.checked := True
         else UseMuBox.Checked := False;
      ParamForm.TempEdit.Text := FloatToStrF(S.Temperature-273.15,ffFixed, 4,1);
      ParamForm.MuEdit.Text := FloatToStrF(S.Mu, ffFixed, 4, 4);
      ParamForm.MaxItEdit.Text := IntToStr(ItMax);
      ParamForm.TolerEdit.Text := FloatToStrF(Toler, ffExponent, 3, 8);

end;                                    {End WriteScreen}

procedure TParamForm.FormActivate(Sender: TObject);
begin
   WriteScreen;
end;                                    {End FormActivate}


procedure TParamForm.TempEditExit(Sender: TObject);
Var Celsius : double;

begin
   Celsius := S.Temperature - 273.15;
   TempEdit.Text := WriteRealEditFix(TempEdit.Text, Celsius, -10, 300);
   S.Temperature := Celsius + 273.15;
end;

procedure TParamForm.MuEditExit(Sender: TObject);
begin
   MuEdit.Text := WriteRealEditFix(MuEdit.Text, S.Mu, 0, 10);
end;


procedure TParamForm.TolerEditExit(Sender: TObject);
begin
   TolerEdit.Text := WriteRealEditExp(TolerEdit.Text, Toler, 1e-10, 0.001);
end;

procedure TParamForm.MaxItEditExit(Sender: TObject);
begin
    MaxItEdit.Text := WriteIntEdit(MaxItEdit.Text, ItMax, 5, 1000);
end;

{The 'Done' button closes the form}

procedure TParamForm.ExitBtnClick(Sender: TObject);
begin
  ParamForm.Close;
end;

procedure TParamForm.ThermoBoxClick(Sender: TObject);
begin
    If ThermoBox.Checked then S.ThermoCalc := True
     else S.ThermoCalc := False;
end;

procedure TParamForm.MuBoxClick(Sender: TObject);
begin
   If MuBox.Checked then S.FindMu := False
     else S.FindMu := True;
end;

procedure TParamForm.UseMuBoxClick(Sender: TObject);
begin
    If UseMuBox.Checked then S.UseMu := True
     else S.UseMu := False;
end;


procedure TParamForm.HelpBtnClick(Sender: TObject);
begin
    HelpIndex := 9;
    TitrHelpForm.ShowModal;
end;

end.
